package com.s07.h01a.utils;

import com.s07.h01a.model.GoldUser;
import com.s07.h01a.model.StandardUser;
import com.s07.h01a.model.User;

public class UserUtils {

	public static User[] getUsers(String[] strings) {

	User[] users= {null,null,null};
		
		for (String string : strings) {

		
			String[] userDetails = string.split(",");

					
			if (userDetails[2].contentEquals("standard")) {
				StandardUser standardUser = new StandardUser(userDetails[0],
						userDetails[1]);
			users[0]= standardUser;
			}

			if (userDetails[2].contentEquals("gold")) {
				GoldUser goldUser = new GoldUser(userDetails[0], userDetails[1]);
				users[1]= goldUser;
			}
			if (userDetails[2].contentEquals("normal")) {
				User user = new User(userDetails[0], userDetails[1]);
				users[2]= user;
			}

		}

		return users;
	}


	public static void listUsers(User[] users) {

		for (User user : users) {
			System.out.println(user);

			System.out.println(user.showProducts());

			if (user instanceof StandardUser) {
				System.out
						.println(((StandardUser) user).showDiscountProducts());
			}
			if (user instanceof GoldUser) {
				System.out
				.println(((GoldUser) user).showExtraProducts());
			}
		}
	}
}
